#include "mmTest_WhiteBalance.h"

_mmTest_WhiteBalance mmTest_WhiteBalance;

bool _mmTest_WhiteBalance::_Init() {



	Flag_Inited = TRUE;
	return TRUE;
}

bool _mmTest_WhiteBalance::RunTest(uuByteFig& ByteFig) {
	Mat FigMat = xx::ByteFigToMat(ByteFig);
	if (FigMat.rows == 0 || FigMat.cols == 0 || FigMat.channels() == 0) {
		return false;
	}

	cvtColor(FigMat, FigMat, CV_BGR2GRAY);
	
	for (int i = 0; i < RoiNum; i++) {
		Mat FigMat_Temp = FigMat(Range(Regions[i].x, Regions[i].y), Range(Regions[i].x + Regions[i].width, Regions[i].y + Regions[i].height));
		Scalar BGR_Value = sum(FigMat_Temp);
		ColorR[i] = (int)BGR_Value[2] / Regions[i].area();
		ColorG[i] = (int)BGR_Value[1] / Regions[i].area();
		ColorB[i] = (int)BGR_Value[0] / Regions[i].area();
	}

	return TRUE;
}